package com.zst.licesingservice.controller;

import com.zst.licesingservice.client.OrganizationDiscoveryClient;
import com.zst.licesingservice.client.OrganizationDiscoveryFeignVer;
import com.zst.licesingservice.model.License;
import com.zst.licesingservice.model.Organization;
import com.zst.licesingservice.service.LicenseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/v1/organizations/{organizationId}/licenses")
public class LicenseServiceController {
    @Autowired
    public LicenseService licenseService;

    @Autowired
    public OrganizationDiscoveryClient client;

    @Autowired
    public OrganizationDiscoveryFeignVer feignClient;

    @GetMapping("/{licenseId}")
    public License getLicenses(
            @PathVariable("organizationId") String organizationId,
            @PathVariable("licenseId") String licenseId){
        return licenseService.getLicense(organizationId, licenseId);
    }

    @GetMapping("/{licenseId}/{clientType}")
    public License getLicenseWithClient(
        @PathVariable("organizationId") String organizationId,
        @PathVariable("licenseId") String licenseId,
        @PathVariable("clientType") String clientType){

        return licenseService.getLicense(organizationId, licenseId, clientType);
    }

    @GetMapping("/getOrgByRemoteCall")
    public Organization getOrgByRemoteCall(@PathVariable("organizationId") String organizationId){
        return client.getOrganization(organizationId);
    }

    @GetMapping("/getOrgByFeign")
    public Organization getOrgByFeign(@PathVariable("organizationId") String organizationId){
        return feignClient.getOrganization(organizationId);
    }
}
